package service;
import org.apache.log4j.Logger;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import utils.DaoUtil;
import beans.DeliveryOrderQuery;
import domain.DeliveryOrder;
/** 
 *订单业务处理
 */
public class DeliveryOrderService {
	/**
	 * Logger for this class  
	 */
	private static final Logger logger = Logger.getLogger(DeliveryOrderService.class);
	/**
	 * Hibernate SessionFactory. 
	 */ 
	private SessionFactory sessionFactory;
	/** 查询信息.
	 *@param deliveryOrderQuery 
	 */
	public void queryDeliveryOrders(DeliveryOrderQuery deliveryOrderQuery) {
	    DaoUtil.doPagedQuery(sessionFactory.getCurrentSession(), deliveryOrderQuery);
	}
	/**
	 * set sessionfactory
	 * @param pSessionFactory factory
	 */
	public void setSessionFactory(SessionFactory pSessionFactory) {
	    sessionFactory = pSessionFactory;
	}
	/** 
	 *@param pIds pIds 
	 */
	public void delDeliveryOrderByIDs(String[] pIds) {
		Integer[] ids=new Integer[pIds.length];
		for(int i=0;i<pIds.length;i++){
			ids[i]=Integer.valueOf(pIds[i]);
		}
	    Session session = sessionFactory.getCurrentSession();
	    String hsql = "delete from DeliveryOrder where id in(:id)";
	    int count = session.createQuery(hsql).setParameterList("id", ids)
	            .executeUpdate();
	    logger.info("delete s count " + count);
	}
	/**
	 * 通过主键取得对象信息.
	 * @param id 
	 * @return DeliveryOrder
	 */
	public DeliveryOrder getDeliveryOrderById(String id) {
		   int typeId=Integer.valueOf(id);
			return (DeliveryOrder) sessionFactory.getCurrentSession().get(DeliveryOrder.class, typeId);
	}
	/**
	 * @param deliveryOrder 要添加的对象. 
	 */
	public void addDeliveryOrder(DeliveryOrder deliveryOrder) {
	    sessionFactory.getCurrentSession().save(deliveryOrder);
	    logger.info("created new DeliveryOrder " + deliveryOrder.getId());
	}
	/**
	 * @param deliveryOrder 要修改的对象.
	 */
	public void updateDeliveryOrder(DeliveryOrder deliveryOrder) {
	    sessionFactory.getCurrentSession().update(deliveryOrder);
	    logger.info("update DeliveryOrder " + deliveryOrder.getId());
	}
}
